//
//  companyDetailsViewController.m
//  OfferJob
//
//  Created by 河南动力无限科技有限公司 on 17/7/12.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "companyDetailsViewController.h"
#import "companyDetailsViewCell.h"

@interface companyDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView* tableview;
@property (nonatomic,strong)NSMutableArray*listarray;
@property (nonatomic,strong)NSMutableDictionary*infoDic;
@end

@implementation companyDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _listarray=[[NSMutableArray alloc]init];
    _infoDic=[[NSMutableDictionary alloc]init];
    _tableview=[[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.backgroundColor=backgroundcolor;
    [_tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableview registerClass:[companyDetailsViewCell class] forCellReuseIdentifier:@"companyDetailsViewCell"];
    [self.view addSubview:_tableview];
    
 
    [self getUserInfo];
    
}

// 获取
-(void)getUserInfo{
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_GET;
    requestModel.appendUrl = @"/Task/user_company_info";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:self.uidcompany forKey:@"uid"];
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"请求的结果是%@",result.data);
            _infoDic=[result.data objectForKey:@"info"];
            _listarray=[result.data objectForKey:@"list"];
                   [self  setUI];
            [_tableview reloadData];
            
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
}


- (void)setUI{
    UIView *viewTo=[[UIView alloc]init];
    viewTo.backgroundColor=blackTextColor;
    
   
    UIView *viewTop=[[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, 90*kAppScale)];
    viewTop.backgroundColor=[UIColor whiteColor];
    [viewTo  addSubview:viewTop];
    
    
    UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(25*kAppScale, 10*kAppScale, 35*kAppScale, 35*kAppScale)];
    [imageView setImageWithURL:[NSURL URLWithString:[_infoDic objectForKey:@"header_pic"]] placeholderImage:[UIImage imageNamed:@""]];
    imageView.layer.cornerRadius=imageView.height/2;
    imageView.clipsToBounds=YES;
    [viewTop  addSubview:imageView];
    
    UILabel*nameLB=[[UILabel alloc]initWithFrame:CGRectMake(imageView.right+10*kAppScale,15*kAppScale,SCREEN_WIDTH-imageView.width-10*kAppScale, 30*kAppScale)];
    nameLB.textColor=[UIColor blackColor];
    nameLB.text=[NSString stringWithFormat:@"%@",[_infoDic objectForKey:@"name"]];
    nameLB.textAlignment=NSTextAlignmentLeft;
    nameLB.font=[UIFont systemFontOfSize:15*kAppScale];
    [viewTop addSubview:nameLB];
    NSString * fei=[NSString stringWithFormat:@"评分：%@",[_infoDic objectForKey:@"credit_score"]];
    NSString* iconStr;
    if ([[_infoDic objectForKey:@"credit_score"]isEqualToString:@"1"]) {
    iconStr=@"icon_bao";
    }else{
    iconStr=@"icon_bozj";
    }
    NSString* iconSr;
    if ([[_infoDic objectForKey:@"is_renzheng"]isEqualToString:@"1"]) {
        iconSr=@"icon_weirenzheng";
    }else{
       iconSr=@"icon_weirenzhengg";
    }
    
    
    
    NSArray*iconArrry=[NSArray arrayWithObjects:iconStr,iconSr,@"icon_pingfen", nil];
    NSArray*arrtTitle=[NSArray arrayWithObjects:@"保证金",@"已认证企业",fei, nil];
    CGFloat Width=SCREEN_WIDTH/3;
    for (int i=0; i<arrtTitle.count; i++) {
        UIButton *buttonshow=[[UIButton alloc]initWithFrame:CGRectMake(i*Width,imageView.bottom, Width,  45*kAppScale)];
        buttonshow .titleLabel.font=[UIFont systemFontOfSize:13*kAppScale];
        [buttonshow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [buttonshow setTitle:arrtTitle[i] forState:UIControlStateNormal];
        [buttonshow setTitleColor:maincolor forState:UIControlStateSelected];
        [buttonshow setImage:[UIImage imageNamed:iconArrry[i]]forState:UIControlStateNormal];
        buttonshow.tag=100+i;
        //        [buttonshow setImage:[UIImage imageNamed:@"arrow_2"] forState:UIControlStateSelected];
        [buttonshow TiaoZhengButtonWithOffsit:5 TextImageSite:0];
        [buttonshow addTarget:self action:@selector(shoudata:) forControlEvents:UIControlEventTouchUpInside];
        [viewTop addSubview:buttonshow];
  
    }

    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, viewTop.bottom, SCREEN_WIDTH, 12*kAppScale)];
    view.backgroundColor=backgroundcolor;
    [viewTo addSubview:view];
    
    
    UIView* middVi=[[UIView alloc]initWithFrame:CGRectMake(0,view.bottom, SCREEN_WIDTH,190*kAppScale)];
    middVi.backgroundColor=[UIColor whiteColor];
    [viewTo addSubview:middVi];
    
    UILabel* contenLB=[[UILabel  alloc]initWithFrame:CGRectMake(10*kAppScale, 0*kAppScale, SCREEN_WIDTH-20*kAppScale, 80*kAppScale)];
    contenLB.numberOfLines=0;
    contenLB.font=[UIFont systemFontOfSize:13*kAppScale];
    contenLB.textColor=blackTextColor;
    contenLB.text=[NSString stringWithFormat:@"%@",[_infoDic objectForKey:@"desc"]];
    [middVi addSubview:contenLB];
    
    UIImageView*imagView=[[UIImageView alloc]initWithFrame:CGRectMake(10*kAppScale, contenLB.bottom+10*kAppScale,SCREEN_WIDTH-20*kAppScale, 90*kAppScale)];
    imagView.image=[UIImage imageNamed:@"icon_bjj"];
    [middVi addSubview:imagView];
    
    
    UIView* vie=[[UIView alloc]initWithFrame:CGRectMake(0, middVi.bottom, SCREEN_WIDTH, 12*kAppScale)];
    vie.backgroundColor=backgroundcolor;
    [viewTo addSubview:vie];
    
    
    
    UIImageView* viewjing=[[UIImageView alloc]initWithFrame:CGRectMake(0,vie.bottom,SCREEN_WIDTH, 44*kAppScale)];
    viewjing.image=[UIImage imageNamed:@"icon_bjj"];
    [viewTo addSubview:viewjing];
    
    
    UILabel*labletitle=[[UILabel alloc]initWithFrame:CGRectMake(10*kAppScale, 0, SCREEN_WIDTH, 44*kAppScale)];
    labletitle.text=@"每日精品";
    labletitle.textColor=[UIColor blackColor];
    labletitle.font=[UIFont systemFontOfSize:14*kAppScale];
    [viewjing addSubview:labletitle];
    
 
    
    viewTo.height=viewjing.bottom;
    [_tableview  setTableHeaderView:viewTo];

}
- (void)shoudata:(UIButton*)btn{


}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listarray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary* _dic=_listarray [indexPath.row];
    companyDetailsViewCell *cell = (companyDetailsViewCell *)[tableView dequeueReusableCellWithIdentifier:@"companyDetailsViewCell" forIndexPath:indexPath];
    cell.imageView.backgroundColor=[UIColor redColor];
    NSString* dayname;
    if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"1"]) {
        dayname=@"天";
    }else if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"2"]) {
        dayname=@"小时";
    }else  if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"3"]){
        dayname=@"次";
    }else{
        dayname=@"预算";
    }
        [cell .imagView setImageWithURL:[NSURL URLWithString:    [NSString stringWithFormat:@"%@",_dic[@"title_pic"]]] placeholderImage:[UIImage imageNamed:@""]];
       cell.titleLB.text=[NSString stringWithFormat:@"%@",_dic[@"title"]];
    NSString* name;
    if ([[_dic objectForKey:@"status"]isEqualToString:@"1"]) {
        name=@"任务进行中";
    }else if ([[_dic objectForKey:@"status"]isEqualToString:@"2"]) {
        name=@"报名截止";
    }else  if ([[_dic objectForKey:@"status"]isEqualToString:@"3"]){
        name=@"任务过期";
    }else  if ([[_dic objectForKey:@"status"]isEqualToString:@"4"]){
        name=@"任务结束";
    }
    
    else{
        name=@"预算";
    }
    cell.nameLB.text=name;
      cell.numLB.text= [NSString stringWithFormat:@"人数：%@人",_dic[@"num"]];
//    cell.moneyLB.text=@"80元/天";heise14
    cell. moneyLB.attributedText=[[NSString stringWithFormat:@"<red14>%@元</red14><heise12>/%@</heise12>",_dic[@"jiesuan_price"],dayname]attributedStringWithStyleBook:[self Style]];
    cell.timeLB.text=[NSString stringWithFormat:@"%@-%@", [NSString stringWithFormat:@"%@",_dic[@"date_starttime"]], [NSString stringWithFormat:@"%@",_dic[@"date_endtime"]]];
    
    return cell;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80*kAppScale;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.hidesBottomBarWhenPushed=YES;
//    sendDetailViewController*sendDetailVC=[[sendDetailViewController alloc]init];
//    [self.navigationController pushViewController:sendDetailVC animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
